//package com.shanghaionstar.notification.util;
//
//import org.apache.http.HttpEntity;
//import org.apache.http.HttpException;
//import org.apache.http.HttpRequest;
//import org.apache.http.HttpRequestInterceptor;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.InputStreamEntity;
//import org.apache.http.impl.client.DefaultHttpClient;
//import org.apache.http.params.CoreConnectionPNames;
//import org.apache.http.protocol.BasicHttpContext;
//import org.apache.http.protocol.HttpContext;
//
//import java.io.ByteArrayInputStream;
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.zip.GZIPInputStream;
//
//@SuppressWarnings("deprecation")
//public class HttpUtils {
//	private final static int TIME_OUT = 60 * 1000;
//	static String[] Cookie = { "cookie1", "cookie2" };
//	public static String httpRequest(String url, String xml, int timeOut) throws Exception {
//		DefaultHttpClient httpClient = new DefaultHttpClient();
//		httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
//			public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
//				if (!request.containsHeader("Accept-Encoding")) {
//					request.addHeader("Accept-Encoding", "gzip");
//				}
//			}
//		});
//		httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeOut);
//		httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeOut);
//		httpClient.getParams().setParameter("http.protocol.handle-redirects", false);
//		HttpPost post = new HttpPost(url);
//		post.setHeader("Content-type", "application/xml");
//		if (xml != null) {
//			byte[] data = xml.getBytes("UTF-8");
//			ByteArrayInputStream input = new ByteArrayInputStream(data);
//			HttpEntity requestEntity = new InputStreamEntity(input, data.length);
//			post.setEntity(requestEntity);
//		}
//		HttpResponse response = httpClient.execute(post);
//		String result = "";
//		try {
//			GZIPInputStream inputStream = new GZIPInputStream(response.getEntity().getContent());
//			result = encodeConvert(inputStream);
//		} catch (Exception e) {
//			result = encodeConvert(response.getEntity().getContent());
//		}
////		result = encodeConvert(response.getEntity().getContent());
//		httpClient.getConnectionReuseStrategy().keepAlive(response, new BasicHttpContext());
//		if (response.getHeaders("Set-Cookie") != null && response.getHeaders("Set-Cookie").length == 2) {
//			Cookie[0] = response.getHeaders("Set-Cookie")[0].getValue();
//			Cookie[1] = response.getHeaders("Set-Cookie")[1].getValue();
//		}
//
//		return result;
//	}
//
//	private static String encodeConvert(InputStream input) throws Exception {
//		ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
//		byte[] buff = new byte[100];
//		int rc = 0;
//		while ((rc = input.read(buff, 0, 100)) > 0) {
//			swapStream.write(buff, 0, rc);
//		}
//		byte[] in2b = swapStream.toByteArray();
//		return new String(in2b, "UTF-8");
//	}
//}